<template>
  <div class="common-layout">
    <el-container>

      <!-- 顶部栏 -->
      <el-header style="height: 7vh;background-color: #fff;">
        <el-row :gutter="10">
          <!-- 标题 -->
          <el-col :span="4">
            <div id="title">
              <!--图形-->
              <div id="graphic">
                <div id="triangle"></div>
                <div id="square"></div>
                <div id="circle"></div>
              </div>
              <span id="tText">智慧养老</span>
            </div>
          </el-col>
          <!-- 顶部栏菜单 -->
          <el-col :span="17">
            <el-menu mode="horizontal"
                     :default-active="activeItemIndex"
                     style="border-bottom: 0 solid var(--el-border-color);height: 7vh;">
              <el-menu-item :index="headerMenuIndex[0]" class="top-menu-item"
                            @click="changeAsideMenu(headerMenuIndex[0])">服务管理
              </el-menu-item>
              <el-menu-item :index="headerMenuIndex[1]" class="top-menu-item"
                            @click="changeAsideMenu(headerMenuIndex[1])">费用管理
              </el-menu-item>
              <el-menu-item :index="headerMenuIndex[2]" class="top-menu-item"
                            @click="changeAsideMenu(headerMenuIndex[2])">统计管理
              </el-menu-item>
              <el-menu-item :index="headerMenuIndex[3]" class="top-menu-item"
                            @click="changeAsideMenu(headerMenuIndex[3])">系统管理
              </el-menu-item>
            </el-menu>
          </el-col>

          <!-- 头像和下拉菜单 -->
          <el-col :span="3">
            <el-avatar :size="35" :src="circleUrl" style="margin-top: 10px;float: left"/>
            <el-dropdown @command="handleCommand" :hide-on-click="true" style="display: inline-block;height: 7vh;margin-top: 20px;">
              <span v-if="user" style="font-size: 16px;margin-left: 10px;">
         {{user.username}}
              </span>
              <span else style="font-size: 16px;margin-left: 10px;">
        未登录

              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="a">主页</el-dropdown-item>
                  <el-dropdown-item command="b" >退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-header>

      <el-container style="height: 93vh;">
        <!-- 侧边栏 -->
        <el-aside width="235px"
                  style="background-color: #fff;margin-top: 1px;">
          <el-menu active-text-color="rgb(4, 104, 255)"
                   :collapse-transition="false"
                   router
                   style="border-right: 0 solid #fff;">

            <!-- 服务管理菜单 -->
            <el-menu-item index="/homeContent" v-if="activeItemIndex==1">
              <i class="iconfont icon-home"></i>
              <span>首页</span>
            </el-menu-item>
            <el-sub-menu index="1-2" v-if="activeItemIndex==1">
              <template #title>
                <i class="iconfont icon-Reception" style="font-weight: 600"></i>
                <span>接待管理</span>
              </template>
              <el-menu-item index="/receptionRegistration"><span class="sub-item">接待登记</span></el-menu-item>
              <el-menu-item index="/visitorRegistration"><span class="sub-item">来访登记</span></el-menu-item>
              <el-menu-item index="/patientInfo"><span class="sub-item">老人信息查询</span></el-menu-item>
              <el-menu-item index="/bedQuery"><span class="sub-item">床位查询</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="1-3" v-if="activeItemIndex==1">
              <template #title>
                <i class="iconfont icon-users"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/patientArchives"><span class="sub-item">用户档案</span></el-menu-item>
              <el-menu-item index="/application"><span class="sub-item">外出登记</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="1-4" v-if="activeItemIndex==1">
              <template #title>
                <i class="iconfont icon-healthcare"></i>
                <span>护理管理</span>
              </template>
              <el-menu-item index="/service-pro"><span class="sub-item">服务项目管理</span></el-menu-item>
              <el-menu-item index="/nurse-grade"><span class="sub-item">护理等级</span></el-menu-item>
              <el-menu-item index="/nurse-management"><span class="sub-item">护理管理</span></el-menu-item>
              <el-menu-item index="/nurse-report"><span class="sub-item">护理报表</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="1-5" v-if="activeItemIndex==1" collapse-transition="false">
              <template #title>
                <i class="iconfont icon-hospital-bed"></i>
                <span>床位管理</span>
              </template>
              <el-menu-item index="/bedManager"><span class="sub-item">床位管理</span></el-menu-item>
              <el-menu-item index="/turnBedManager"><span class="sub-item">转床管理</span></el-menu-item>
              <el-menu-item index="/turnRoomManager"><span class="sub-item">转房管理</span></el-menu-item>
              <el-menu-item index="/bedSetting"><span class="sub-item">床位设置</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="1-6" v-if="activeItemIndex==1">
              <template #title>
                <i class="iconfont icon-meals"></i>
                <span>膳食管理</span>
              </template>
              <el-menu-item index="/MealsManagement"><span class="sub-item">膳食类目管理</span></el-menu-item>
              <el-menu-item index="/OrderingService"><span class="sub-item">点餐服务</span></el-menu-item>
              <el-menu-item index="/MealsPlan"><span class="sub-item">膳食计划</span></el-menu-item>
              <el-menu-item index="/DeliveryRecord"><span class="sub-item">配送记录</span></el-menu-item>
            </el-sub-menu>

            <!-- 费用管理菜单 -->
            <el-menu-item index="/nothing" v-if="activeItemIndex==2">
              <i class="iconfont icon-prestore" style="font-size: 28px"></i>
              <div>预存管理</div>
            </el-menu-item>
            <el-menu-item index="/nothing" v-if="activeItemIndex==2">
              <i class="iconfont icon-zijinmingximei"></i>
              <div>记账管理</div>
            </el-menu-item>
            <el-menu-item index="/nothing" v-if="activeItemIndex==2">
              <i class="iconfont icon-unsubscribe"></i>
              <div>退住结算</div>
            </el-menu-item>
            <el-menu-item index="/nothing" v-if="activeItemIndex==2">
              <i class="iconfont icon-settlement" style="font-size: 30px"></i>
              <div>结算记录</div>
            </el-menu-item>
            <el-menu-item index="/nothing" v-if="activeItemIndex==2">
              <i class="iconfont icon-paymentrcharge"></i>
              <div>收费项目维护</div>
            </el-menu-item>

            <!-- 统计管理菜单 -->
            <el-sub-menu index="3-1" v-if="activeItemIndex==3">
              <template #title>
                <i class="iconfont icon-Reception" style="font-weight: 600"></i>
                <span>接待来访统计</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">接待统计</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">来访统计</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3-2" v-if="activeItemIndex==3">
              <template #title>
                <i class="iconfont icon-users"></i>
                <span>用户管理统计</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">用户建档统计</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">入院登记统计</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">外出登记统计</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">退住登记统计</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3-3" v-if="activeItemIndex==3">
              <template #title>
                <i class="iconfont icon-hospital-bed"></i>
                <span>床位管理统计</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">床位使用情况统计</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3-4" v-if="activeItemIndex==3">
              <template #title>
                <i class="iconfont icon-paymentrcharge"></i>
                <span>费用管理统计</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">预存收退费统计</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">退住汇总统计</span></el-menu-item>
            </el-sub-menu>

            <!-- 系统管理菜单 -->
            <el-sub-menu index="4-1" v-if="activeItemIndex==4">
              <template #title>
                <i class="iconfont icon-renyuanzizhiguanli"></i>
                <span>人事管理</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">员工信息</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">员工离职登记</span></el-menu-item>
              <el-menu-item index="/nothing"><span class="sub-item">员工请假登记</span></el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="4-2" v-if="activeItemIndex==4">
              <template #title>
                <i class="iconfont icon-setting" style="font-size: 30px"></i>
                <span>系统设置</span>
              </template>
              <el-menu-item index="/nothing"><span class="sub-item">角色管理</span></el-menu-item>
            </el-sub-menu>

          </el-menu>
        </el-aside>

        <!-- 内容 -->
        <el-main style="padding: 0 100px;">
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import {reactive, ref, toRefs} from 'vue'

const state = reactive({
  circleUrl:
      'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
})

const {circleUrl} = toRefs(state)
const user = localStorage.user?JSON.parse(localStorage.user):null
const headerMenuIndex = ref(['1', '2', '3', '4']);
const activeItemIndex = ref('1');
const changeAsideMenu = (index) => {
  activeItemIndex.value = index;
}
const handleCommand = (command)=>{
  if (command=='a'){
    location.href="/"
  }else if(command=='b'){
    logout()
  }
}
const logout = ()=>{
  if (confirm("您确认退出登录吗?")){
    localStorage.clear();
    location.href='/login';  //返回首页
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  font-family: 'Microsoft YaHei UI', sans-serif;
  font-weight: 400;
  font-style: normal;
}

i {
  font-size: 25px;
  margin-right: 10px;
  width: 40px;
  text-align: center;
}

.el-menu span {
  padding-top: 5px;
  font-size: 14px;
}

.el-aside::-webkit-scrollbar {
  display: none;
}

#title {
  position: relative;
  top: 5px;
}

#tText {
  font-family: 'Microsoft YaHei UI Bold', 'Microsoft YaHei UI Regular', 'Microsoft YaHei UI', sans-serif;
  font-weight: 700;
  font-style: normal;
  font-size: 26px;
  color: #000000;
  position: absolute;
  margin-left: 25px;
  margin-top: 5px;
  padding: 0;
}

#graphic {
  width: 42px;
  height: 55px;
  overflow: hidden;
  position: relative;
  left: 10px;
  top: -5px;
  display: inline-block;

}

#triangle {
  width: 30px;
  height: 18px;
  background-color: rgb(4, 104, 255);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  margin: 3px auto;
}

#square {
  width: 20px;
  height: 20px;
  background-color: rgb(0, 167, 111);
  float: left;
  /*margin-right: 20px;*/
}

#circle {
  width: 20px;
  height: 20px;
  background-color: rgb(24, 204, 208);
  border-radius: 10px;
  float: right;
}

.top-menu-item {
  padding: 20px;
  font-family: 'Microsoft YaHei UI', sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 16px;
  color: #000000;
}

.sub-item {
  padding-left: 40px;
}
</style>
